//
//  OMOrderEvaluateSelectTableCell.m
//  OMENGO_NEW
//
//  Created by 梁尚嘉 on 2017/5/17.
//  Copyright © 2017年 Kamfat. All rights reserved.
//

#import "OMOrderEvaluateSelectTableCell.h"
@interface OMOrderEvaluateSelectTableCell ()
@property (nonatomic, strong) UIButton *goodButton;
@property (nonatomic, strong) UILabel *goodLabel;
@property (nonatomic, strong) UILabel *negativeLabel;
@property (nonatomic, strong) UIButton *negativeButton;

@end

@implementation OMOrderEvaluateSelectTableCell

- (void)configure
{
    [super configure];

    UIView *line = [UIView new];
    line.backgroundColor = SM_naviShadowColor;
    [self.contentView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView.mas_centerX);
        make.top.equalTo(@(SM_SIZE(80)));
        make.bottom.equalTo(@(SM_SIZE(-80)));
        make.width.equalTo(@.5f);
    }];

    _goodButton = [UIButton new];
    [_goodButton setImage:[UIImage imageNamed:@"ic_order_evaluate_negative"] forState:UIControlStateNormal];
    [_goodButton setImage:[UIImage imageNamed:@"ic_order_evaluate_good_hl"] forState:UIControlStateSelected];
    [self.contentView addSubview:_goodButton];
    [_goodButton addTarget:self action:@selector(buttonTap:) forControlEvents:UIControlEventTouchUpInside];
    [_goodButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(SM_SCREEN_WIDTH/6));
        make.centerY.equalTo(self.contentView.mas_centerY).offset(SM_SIZE(-20));
    }];
    _goodLabel = [UILabel new];
    _goodLabel.font = SM_CFont(35);
    _goodLabel.textColor = HEXCOLOR(@"#A5A5A5");
    _goodLabel.highlightedTextColor = SM_blackColor;
    _goodLabel.text = @"好评";
    [self.contentView addSubview:_goodLabel];
    [_goodLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_goodButton.mas_centerX);
        make.top.equalTo(_goodButton.mas_bottom).offset(SM_SIZE(10));
    }];

    _negativeButton = [UIButton new];
    [_negativeButton setImage:[UIImage imageNamed:@"ic_order_evaluate_good"] forState:UIControlStateNormal];
    [_negativeButton setImage:[UIImage imageNamed:@"ic_order_evaluate_negative_hl"] forState:UIControlStateSelected];
    [_negativeButton addTarget:self action:@selector(buttonTap:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_negativeButton];
    [_negativeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-SM_SCREEN_WIDTH/6));
        make.centerY.equalTo(self.contentView.mas_centerY).offset(SM_SIZE(-20));
    }];
    _negativeLabel = [UILabel new];
    _negativeLabel.font = SM_CFont(35);
    _negativeLabel.textColor = HEXCOLOR(@"#A5A5A5");
    _negativeLabel.highlightedTextColor = SM_blackColor;
    _negativeLabel.text = @"差评";
    [self.contentView addSubview:_negativeLabel];
    [_negativeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_negativeButton.mas_centerX);
        make.top.equalTo(_negativeButton.mas_bottom).offset(SM_SIZE(10));
    }];

    self.type = EOEvaluateTypeGood;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:self.contentView];
    if (CGRectContainsPoint(self.contentView.frame, location)) {
        if (location.x < SM_SCREEN_WIDTH/2) {
            [self buttonTap:_goodButton];
        }else {
            [self buttonTap:_negativeButton];
        }
    }
}

- (void)setType:(EOEvaluateType)type
{
    _type = type;
    if (type == EOEvaluateTypeGood) {
        self.goodLabel.highlighted = YES;
        self.goodButton.selected = YES;
        self.negativeLabel.highlighted = NO;
        self.negativeButton.selected = NO;
    }else {
        self.goodLabel.highlighted = NO;
        self.goodButton.selected = NO;
        self.negativeLabel.highlighted = YES;
        self.negativeButton.selected = YES;
    }
}

- (void)buttonTap:(id)sender
{
    if (sender == _goodButton) {
        self.type = EOEvaluateTypeGood;
    }else {
        self.type = EOEvaluateTypeNegative;
    }
}

+ (CGFloat)cellHeight
{
    return SM_SIZE(300);
}

@end
